package com.unei.scala.demo

class FileMatcher {
    private def filesHere = (new java.io.File(".")).listFiles()

    def filesEnding(query: String) =
        for (file <- filesHere; if file.getName().endsWith(query))
            yield file

    def filesContaining(query: String) =
        for (file <- filesHere; if file.getName.contains(query))
            yield file

    def filesRegex(query: String) =
        for (file <- filesHere; if file.getName.matches(query))
            yield file

    def filesMatching(query: String, matcher: (String, String) => Boolean) = {
        for (file <- filesHere; if matcher(file.getName, query))
            yield file
    }
    
    def nFilesEnding(query:String)=filesMatching(query,_.endsWith(_))
    def nFilesContains(query:String)=filesMatching(query,_.contains(_))
    def nFilesRegex(query:String)=filesMatching(query,_.matches(_))
    
    def containsneg(nums:List[Int])=nums.exists(_<0)
    def containsOdd(nums:List[Int])=nums.exists(_%2==1)
}